package dc.singleNumber;

import java.util.Arrays;
import java.util.List;

import bbb.sss.Utils;
import dc.DCB;
import dc.DCBBonus;
import dc.HistoryData;
import dc.Outcome;
import dc.Proposal;
import dc.utils.DCBUtils;
import distribution.SchemeItem;

public class SingleNumberGenarator {

	public static Proposal createProposal(HistoryData hd){
		Proposal pr = new Proposal();
		int b = Utils.randomNumber(16);
		List<Integer> blue = Arrays.asList(new Integer[]{b});
		int multipe = 1;

		if(hd!=null){
			if(hd.getHo()!=null && hd.getHo().size()>0){
				Outcome out = hd.getHo().get(hd.getHo().size()-1);
				out.compute();
				int lastMultipe = out.getTotalMultipe();
				int lastBonusMultipe = out.getBonusMultipe()[DCBBonus.AW_LEVEL_6];
				if(lastBonusMultipe==0){
					multipe = 2 * lastMultipe;
				}else{
					multipe = 1;
				}
				
				blue = out.getProposal().getItems().get(0).getBlue().getCodes();
			}
		}
		
		for(int i = 1; i <= multipe ; i++){
			List<Integer> reds = DCBUtils.randomCodes(33, 6);
			DCB dcb = DCBUtils.createDCB(reds, blue, multipe);
			pr.addItem(dcb);
		}
		return pr;
	}
	
	private static Proposal fixedProposal(HistoryData hd) {
		
		List<Integer> list0 = Arrays
				.asList(new Integer[] { 1, 7, 8, 15, 19, 31 });
		List<Integer> list1 = Arrays.asList(new Integer[] { 2, 5, 14, 17, 21,
				33 });
		List<Integer> list2 = Arrays.asList(new Integer[] { 6, 10, 12, 13, 22,
				27 });
		List<Integer> list3 = Arrays.asList(new Integer[] { 9, 11, 18, 20, 23,
				32 });
		List<Integer> list4 = Arrays.asList(new Integer[] { 4, 24, 25, 26, 28,
				30 });

		SchemeItem red = new SchemeItem(list0);
		SchemeItem blue = new SchemeItem( Arrays.asList(new Integer[]{10}));
		DCB fixedDcb = new DCB(red, blue, 1);
		
		List<Outcome> ol = hd.getHo();
		Outcome c1 = ol.get(ol.size()-1);
		Outcome c2 = ol.get(ol.size()-2);
		Outcome c3 = ol.get(ol.size()-3);
		Outcome c4 = ol.get(ol.size()-4);
		
		DCB cc1 = c1.getCurrent();
		DCB cc2 = c2.getCurrent();
		DCB cc3 = c3.getCurrent();
		DCB cc4 = c4.getCurrent();
		
		Proposal pr = new Proposal();
		pr.addItem(fixedDcb);
		pr.addItem(new DCB(new SchemeItem(list1), cc1.getBlue(), 1));
		pr.addItem(new DCB(new SchemeItem(list2), cc2.getBlue(), 1));
		pr.addItem(new DCB(new SchemeItem(list3), cc3.getBlue(), 1));
		pr.addItem(new DCB(new SchemeItem(list4), cc4.getBlue(), 1));
		
		return pr;
	}
	
	public static void main(String[] args){
		HistoryData hd = DCBUtils.createHistory(1600);

		for(int i = 1600 ; i < 3100; i++){
			Proposal pr = fixedProposal(hd);
			Outcome co = new Outcome();
			co.setNumber(i);
			co.setProposal(pr);
			co.setCurrent(DCBUtils.randomDCB());

			co.compute();
			hd.getHo().add(co);
		}
		
		System.out.println(hd.sumary());
	}
	
}
